package com.xh.bussiness.tiku.service.impl;

import com.xh.bussiness.tiku.bean.request.QuestionTitleRequest;
import com.xh.bussiness.tiku.model.QuestionTitle;
import com.xh.bussiness.tiku.dao.QuestionTitleMapper;
import com.xh.bussiness.tiku.service.IQuestionTitleService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 常用题干表 服务实现类
 * </p>
 *
 * @author Pitt Cheung
 * @since 2021-09-02
 */
@Service
public class QuestionTitleServiceImpl extends BaseServiceImpl<QuestionTitleMapper, QuestionTitle> implements IQuestionTitleService {
    @Override
    public XhPage queryQuestionTitlePage(XhPage page, QuestionTitleRequest bean) {
        QueryWrapper qw = new QueryWrapper<QuestionTitle>();
        //拼装条件
        qw = prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page, qw);
    }

    @Override
    public List queryQuestionTitle(QuestionTitleRequest bean) {
        QueryWrapper qw = new QueryWrapper<QuestionTitle>();
        //拼装条件
        qw = prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     *
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(QuestionTitleRequest bean, QueryWrapper qw) {
        if (bean.getIds() != null && bean.getIds().length > 0) {
            qw.in("id", bean.getIds());
        }
        if (StringUtils.isNotEmpty(bean.getSubject())) {
            qw.eq("subject", bean.getSubject());
        }
        if (bean.getQuestionType() != null && bean.getQuestionType() != 0) {
            qw.eq("question_type", bean.getQuestionType());
        }
        return qw;
    }
}
